package com.example.security.service;

import com.example.security.bean.UserInfo;
import com.example.security.dao.UserInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @author LiYuhang
 * @version 0.1
 * @application
 */
@Service
public class UserInfoService  implements UserDetailsService {

    @Autowired
    UserInfoMapper userInfoMapper;
    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        UserInfo user = userInfoMapper.findEntityByUserName(s);
        if (user == null) {
            throw new UsernameNotFoundException("用户不存在!");
        }
        user.setSysRoleList(userInfoMapper.findRoleListByUserId(user.getUid()));
        return user;
    }
}
